<!--
 * @Author: jay
 * @Date: 2021-08-18 09:21:49
 * @LastEditTime: 2021-08-18 09:49:19
 * @LastEditors: Please set LastEditors
 * @Description: 居中
 * @FilePath: \Briup\Common\study\2-css\3-其他样式规则\8-center.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>盒子居中</title>
    <style>
        body{
            margin: 0;
            
        }
        .container{
            box-sizing: border-box;
            background-color: #ccc;
            height: 400px;
            padding: 1px;

            /* padding: 150px;                                  盒子垂直居中*/
        }
        .box{
            height: 100px;
            background-color: skyblue;
            width: 100px;

            /*margin: 0 auto;                                  盒子水平居中 */

            margin-left: 50%;
            position: relative;
            left: -50px;                                     /* 通过定位方式水平居中 */

            margin-top: 149px;                              /*与容器的padiing结合达成盒子的垂直居中  */
            
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="box">box</div>
    </div>
    
</body>
</html>